/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TesteJFrame.java
 *
 * Created on 14/09/2009, 19:40:17
 */

package dominio.baca;

import dominio.util.DominioUtil;
import java.util.List;
import javax.swing.DefaultListModel;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author pbarros
 */
public class TesteJFrame extends javax.swing.JInternalFrame {
 private DefaultListModel listModel;
 private DefaultListModel listModelNecessario;
 private DefaultListModel listModelPossivel;

    /** Creates new form TesteJFrame */
    public TesteJFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */

    private void consultaHQLNodosCasoLista(String nomeCaso) {
        String QUERY_Casoestudo=" select nosc.proprEvidDiagNodosCaso, nosc.posNecesNodoCaso, nodo.nomeNodos " +
//        String QUERY_Casoestudo=" select nosc " +
                " from Nodos as nodo " +
                " inner join nodo.nodoscasos as nosc " +
                " inner join nosc.casoestudo as caes " +
                " where caes.nomeCaso=:nome ";
         try {
            Session session = DominioUtil.getSessionFactory().openSession();
            session.beginTransaction();
            Query q = session.createQuery(QUERY_Casoestudo).setParameter("nome", nomeCaso);
            List resultList = q.list();
            displayResultNodosCaso(resultList);
            session.getTransaction().commit();
        } catch (HibernateException he) {
            
            he.printStackTrace();
        }
    }



    private void displayResultNodosCaso(List resultList) {
        listModelNecessario.clear();
        listModelPossivel.clear();
        String resultProprEvidDiagNodosCaso=null;
        String resultPosNecesNodoCaso=null;
        String resultNomeNodo=null;

        for(int i = 0; i < resultList.size(); i++) {
            Object[] result = (Object[]) resultList.get(i);
//            System.out.println((String) result[0]+" - "+(String) result[1]+" - "+(String) result[2]+" - "+result.length);
            resultProprEvidDiagNodosCaso=(String) result[0];
            resultPosNecesNodoCaso=(String) result[1];
            resultNomeNodo=(String) result[2];
            System.out.println((String) result[0]+" - "+(String) result[1]+" - "+(String) result[2]+" - "+result.length);

            if(resultProprEvidDiagNodosCaso.equals("D")){
                if(resultPosNecesNodoCaso.equals("N")){
                    listModelNecessario.addElement(resultNomeNodo);
                }else{
                    listModelPossivel.addElement(resultNomeNodo);
                }
            }
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();

        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jList1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jList1MouseClicked(evt);
            }
        });
        jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jList1ValueChanged(evt);
            }
        });
        System.out.println("teste"+jList1.getSelectedValue());
        jScrollPane1.setViewportView(jList1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(347, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(109, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged
        // TODO add your handling code here:
        if (evt.getValueIsAdjusting() == false) {

                if (jList1.getSelectedIndex() == -1) {
                //No selection, disable fire button.
                    System.out.println("1 -"+jList1.getSelectedValue());

                } else {
                //Selection, enable the fire button.
                    System.out.println("2 -"+jList1.getSelectedValue());
                }
            }
        
        
    }//GEN-LAST:event_jList1ValueChanged

    private void jList1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MouseClicked
        // TODO add your handling code here:

     //   System.out.println("Mouse cliked "+jList1.getSelectedValue());
    }//GEN-LAST:event_jList1MouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
